//quick sort alg

/*fn quick_sort(arr:&mut [i32]) -> () {
    if arr.len() <= 1 {
        return;
    }


    let pi = partition(arr);
    quick_sort(&mut arr[0..pi]);
    quick_sort(&mut arr[pi+1..]);

}

fn partition(arr:&mut [i32]) -> usize{
    let len = arr.len();
    let pivot = arr[len -1];

    let mut i = 0;

    for j in 0..len - 1 {
        if arr[j] <= pivot {
            arr.swap(i, j);
            i += 1;
        }
    }
    arr.swap(i, len - 1);
    i
}

fn main() {
    let mut arr = [10, 7, 8, 9, 1, 5];

    quick_sort(&mut arr);

    println!("{:?}", arr);
}*/

//factorials

/*fn fact(i: i32) -> i32{
    if i == 0 {
        return 1;
    }
    i * fact(i-1) //f(n) = n * n-1 * n-2 .. 1
}

fn main() {
    println!("{:?}", fact(4));
}*/

// koroche tut pechataet v odnom poryadke potom v drugom

/*fn print_fun(test: i16) {
    if test < 1 {
        return;
    }
    else {
        println!("{}", test);
        print_fun(test - 1);
        println!("{}", test);
    }
}
fn main() {
    print_fun(3);
}*/

//fibonacci

/*fn fib(n: i16) ->  i16 {
    if n == 0 {
        return 0;
    }
    if n == 1 || n == 2 {
        return 1;
    } else {
        return fib(n-1) + fib(n-2); // f(n) = f(n-1) + f(n-2)
    }

}

fn main() {
    let n = 5;
    println!("Fibonacci series of 5 numbers is: ");
    for i in 0..n {
        println!("{}", fib(i));
    }
}*/

// sum of naturalov

/*fn find_sum(n: i16) -> i16 { // f(n) = Σn
    if n== 1 {
        return 1; // f(1) = 1
    }
    return n + find_sum(n-1);// f(n) = n + f(n-1) represantation
}

fn main() {
    let n:i16 = 5;
    println!("{}", find_sum(n));
}*/

// Tower of Hanoi puzzle

fn tower_of_hanoi(n:i16, from_rod:char, to_rod:char, aux_rod:char) -> () {
    if n ==0 {
        return;
    }
    tower_of_hanoi(n-1, from_rod, aux_rod, to_rod);
    println!("move disk {} from rod {} to rod {}.", n, from_rod, to_rod);
    tower_of_hanoi(n-1, aux_rod, to_rod, from_rod);
}

fn main() {
    let n:i16 = 3;
    tower_of_hanoi(n, 'A', 'C', 'B');
}
